package networkSimulation.simulation.animals.statistic

import networkSimulation.statistic.{Statistic, VisualStatistics}
import networkSimulation.simulation.animals.framework._
import networkSimulation.framework.Graph

/**
 * Statistic representing the survival of dinosaurs as a pie chart.
 *
 * @author  Tim Caljé
 *          Jeroen De Raedt
 *          Jorick Van Aken
 */
class DinosaurSurvivalPie [N<%Animal,E<%Hunt[N]] extends Statistic[N,E]{
  private var dinosaur = 0
  private var dinosaurAmounts =List[Int]()


  @Override
  override def generateStatistic(vis:VisualStatistics,path : String){
    var list = List[Int]()
    var strings = List[String]()
    strings::= "Dead"
    strings::= "Alive"
    list::=dinosaurAmounts.last - dinosaurAmounts.head
    list::= dinosaurAmounts.head
    vis.createPie("Dinosaur Survival Ratio",list,strings,path)
  }

  @Override
  override def updateStatistics(graph: Graph[N, E],k:String){
    dinosaur = 0
    for(node: N <- graph.nodes){
      if(node.isInstanceOf[Dinosaur]){
        dinosaur+=1
      }
    }
    key = k
  }

  @Override
  override def loadData(data : xml.NodeSeq){
    dinosaurAmounts ::= (data \\ "Dinosaur").text.toInt
  }

  @Override
  override def toXml(): xml.NodeSeq  = {
    <Stat key={key}>
      <Dinosaur>{ dinosaur }</Dinosaur>
    </Stat>
  }
}